﻿# -*- coding:utf-8 -*-
from django.forms import ModelForm
from django import forms
from django.contrib.auth.models import User
from models import Task, Status, Severity



class TaskForm(ModelForm): 

    def __init__(self, user, *args, **kwargs):
        super(TaskForm, self).__init__(*args, **kwargs)
        self.fields['owner'].initial=user.id        
        self.fields['severity'].initial=Severity.objects.get(default=True).id
        self.fstatus = Status.objects.get(default=True)
        self.freporter = user
        
    def save(self, commit=True):
        self.cleaned_data['status'] = self.fstatus
        self.cleaned_data['reporter'] = self.freporter
        self.cleaned_data['resolution'] = ''
        return super(TaskForm, self).save(commit)    
    '''
    project =  forms.ModelChoiceField(Project.objects.all(), widget=forms.HiddenInput)
    kind =  forms.CharField(widget=forms.HiddenInput)
    status =  forms.CharField(widget=forms.HiddenInput)
    summary = forms.CharField(max_length=100, widget=forms.TextInput(attrs={'size':'80'}))
    description = forms.CharField(widget=forms.Textarea(attrs={'cols':'61','rows':'5'}), required=False)
    reporter = forms.ModelChoiceField(None, widget=forms.HiddenInput)
    owner = forms.ModelChoiceField(None, empty_label=None) 
    subscribers =  forms.ModelMultipleChoiceField(None, widget=forms.CheckboxSelectMultiple, required=False)
    '''
    class Meta:
        model = Task
        exclude = ('status','reporter','resolution',)

'''
class HistoryForm(TaskForm):
    comment = forms.CharField(widget=forms.Textarea(attrs={'cols':'61','rows':'5'}), required=False)
    attachment = forms.FileField(required=False)



class TaskBugHistoryForm(HistoryForm):                                
    resolution  = forms.ChoiceField(required=False, choices=BUG_RESOLUTION_CHOICES)



class TaskFeatureHistoryForm(HistoryForm):
    resolution = forms.ChoiceField(required=False, choices=FEATURE_RESOLUTION_CHOICES)

    
    
class TagForm(ModelForm):

    class Meta:
        model = Tag
'''        